home *** CD-ROM | disk | FTP | other *** search
/ More DosGames 2.0 / MORE - Dosgames 2.0 (Software Company)(1994).iso / dosgames / hedge / common.c next >
Text File  |  1994-09-01  |  6KB  |  203 lines

  1. /****************************************************************************\
  2. *                                                                            *
  3. *  common.c -- functions we use a lot                                        *
  4. *                                                                            *
  5. \****************************************************************************/
  6.  
  7. #define common_c
  8. #include "defs.h"
  9.  
  10. /****************************************************************************\
  11. *                                                                            *
  12. *  abort_game -- exit to DOS if a file or item is not found                  *
  13. *                                                                            *
  14. \****************************************************************************/
  15.  
  16. void abort_game()
  17. {
  18.  
  19.    /* free the mouse handler and extra pages */
  20.  
  21.    fg_mousefin();
  22.    fg_freepage(SPARE);
  23.  
  24.    /* set the video mode and reset screen attributes */
  25.  
  26.    fg_setmode(3);
  27.    fg_reset();
  28.  
  29.    /* print out the abort string and exit */
  30.  
  31.    printf(abort_string);
  32.    printf("\n");
  33.    exit(0);
  34. }
  35.  
  36. /****************************************************************************\
  37. *                                                                            *
  38. *  center_string -- use ROM font, center around a point                      *
  39. *                                                                            *
  40. \****************************************************************************/
  41.  
  42. void center_string(char *string, int x, int y)
  43. {
  44.    int nchar;
  45.    int x1;
  46.  
  47.    /* measure the length of the string */
  48.  
  49.    nchar = strlen(string);
  50.  
  51.    /* calculate the x position */
  52.  
  53.    x1 = x - nchar*4;
  54.    if (x1 < 0) x1 = 0;
  55.  
  56.    /* move to the location and print the string */
  57.  
  58.    fg_move(x1,y);
  59.    fg_print(string,nchar);
  60. }
  61.  
  62. /****************************************************************************\
  63. *                                                                            *
  64. *  flushkey -- flush out the keystroke buffer                                *
  65. *                                                                            *
  66. \****************************************************************************/
  67.  
  68. void flushkey()
  69. {
  70.    unsigned char key,aux;
  71.  
  72.    /* just keep reading keys until there aren't any */
  73.  
  74.    do
  75.       fg_intkey(&key,&aux);
  76.    while (key+aux > 0);
  77. }
  78.  
  79. /****************************************************************************\
  80. *                                                                            *
  81. *  init_graphics -- initialize the graphics environment                      *
  82. *                                                                            *
  83. \****************************************************************************/
  84.  
  85. void init_graphics()
  86. {
  87.     int status;
  88.  
  89.    /* initialize the SVGA kernel */
  90.  
  91.    if (fg_svgainit(0) == 0)
  92.    {
  93.       strcpy(abort_string,"This program requires SVGA.");
  94.       abort_game();
  95.    }
  96.  
  97.    /* make sure an 800x600x256 mode with two pages is available */
  98.  
  99.    if (fg_testmode(26,2) == 0)
  100.    {
  101.       strcpy(abort_string,"This program requires a 1MB SVGA.");
  102.       abort_game();
  103.    }
  104.  
  105.    /* find out what the old video mode is */
  106.  
  107.    old_mode = fg_getmode();
  108.  
  109.    /* initialize 800x600x256 graphics */
  110.  
  111.    fg_setmode(26);
  112.  
  113.    /* find room for another page somewhere (XMS or EMS) */
  114.  
  115.    status = fg_initxms();
  116.    if (status == 0)
  117.       status = fg_allocxms(SPARE);
  118.  
  119.    if (status < 0)
  120.    {
  121.       status = fg_initems();
  122.       if (status == 0)
  123.          status = fg_allocems(SPARE);
  124.    }
  125.  
  126.    if (status < 0)
  127.    {
  128.       strcpy(abort_string,"This program requires XMS or EMS memory.");
  129.       abort_game();
  130.    }
  131.  
  132.    /* benchmark the microprocessor for consistent stall times */
  133.  
  134.    clockspeed = fg_measure();
  135.  
  136.    /* initialize the mouse */
  137.  
  138.    init_mouse();
  139. }
  140.  
  141. /****************************************************************************\
  142. *                                                                            *
  143. *  init_mouse -- initialize the mouse if present                             *
  144. *                                                                            *
  145. \****************************************************************************/
  146.  
  147. void init_mouse()
  148. {
  149.    if (fg_mouseini() > 0)
  150.    {
  151.       mouse = TRUE;
  152.       xmouse = 160;
  153.       ymouse = 100;
  154.       fg_mousemov(xmouse,ymouse);
  155.       fg_mousespd(4,8);
  156.    }
  157.    else
  158.    {
  159.       strcpy(abort_string,"This program requires a mouse.");
  160.       abort_game();
  161.    }
  162. }
  163.  
  164. /****************************************************************************\
  165. *                                                                            *
  166. *  put_string -- put ROM font at an x and y position on the screen           *
  167. *                                                                            *
  168. \****************************************************************************/
  169.  
  170. void put_string(char *string,int x,int y)
  171. {
  172.    int nchar;
  173.  
  174.    /* determine the length of the string */
  175.  
  176.    nchar = strlen(string);
  177.  
  178.    /* move to desired location and display it */
  179.  
  180.    fg_move(x,y);
  181.    fg_print(string,nchar);
  182. }
  183.  
  184. /****************************************************************************\
  185. *                                                                            *
  186. *  quit_graphics -- return the computer to its original state                *
  187. *                                                                            *
  188. \****************************************************************************/
  189.  
  190. void quit_graphics()
  191. {
  192.    /* free the mouse handler and allocated page */
  193.  
  194.    fg_mousefin();
  195.    fg_freepage(SPARE);
  196.  
  197.    /* reset the mode, fix screen attributes, and exit */
  198.  
  199.    fg_setmode(old_mode);
  200.    fg_reset();
  201.    exit(0);
  202. }
  203.